Skip to content

fix: devspaces sudo support with correct UID and user setup#735

Merged
shatakshiiii merged 3 commits into
ansible:mainfrom
leogallego:fix/devspaces-sudo-support
Apr 22, 2026
Merged

fix: devspaces sudo support with correct UID and user setup#735
shatakshiiii merged 3 commits into
ansible:mainfrom
leogallego:fix/devspaces-sudo-support

Conversation

@leogallego
Copy link
Copy Markdown
Contributor

Summary

  • Remove injected base image user (uid 10001) and recreate with uid 1000 to match the SCC-enforced UID, fixing duplicate /etc/passwd and /etc/group entries that prevented sudo from working
  • Lock the user account (usermod -L) and set /etc/shadow permissions to avoid PAM errors in the workspace container
  • Add ADT_CONTAINER_ENGINE=podman env var to devfile.yaml for tox podman support
  • Guard userdel with id check so the build doesn't break if the base image drops the user account

Based on work by @cgruver in #734 (closed due to GPG signing issues). Incorporates all review feedback from that PR.

Test plan

  • Build the devspaces container image (tox -e devspaces)
  • Launch a Dev Spaces workspace with the built image
  • Verify sudo works without password prompts
  • Verify podman works inside the workspace
  • Verify no duplicate entries in /etc/passwd and /etc/group

Fixes sudo execution in the Dev Spaces workspace image by removing the
injected base image user (uid 10001) and recreating it with uid 1000 to
match the SCC-enforced UID. Adds ADT_CONTAINER_ENGINE=podman to devfile.

Based on work by @cgruver in ansible#734.

Co-Authored-By: cgruver <39659182+cgruver@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@alisonlhart alisonlhart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome stuff.
Can some tests/verification be added? If it's too difficult to add specific tests, we should have a few in-line checks. I suggested one.

Comment thread devspaces/context/setup.sh Outdated
Co-Authored-By: alisonlhart <alisonlhart@users.noreply.github.com>
@leogallego
Copy link
Copy Markdown
Contributor Author

Hi — the fix from this PR is confirmed working in ghcr.io/ansible/ansible-devspaces:v26.4.5 (the old UID 10001 user is gone). However, we're still seeing duplicate /etc/passwd entries at runtime in OpenShift DevSpaces:

user:x:1000:1000::/home/user:/bin/bash
user:x:1000860000:0:user user:/home/user:/bin/bash

The second entry is injected by OpenShift's CRI-O runtime when the SCC assigns a UID from the namespace range. Since the image already has user at UID 1000, this creates a name collision — two user entries with different UIDs.

This causes:

  • getent passwd user resolving to UID 1000, while the process actually runs as 1000860000
  • Potential issues with terminal spawning and environment resolution in che-code

Tracking the runtime behavior issue separately at rhpds/ansible-dev-tools-workspace#10. This may need a different approach for the DevSpaces image (e.g., not pre-creating user in the image, or using a different username to avoid the collision).

@leogallego
Copy link
Copy Markdown
Contributor Author

Follow-up on the sudo fix — we tested on DevSpaces 3.27.0 / OCP 4.21.9 and sudo still doesn't work on either v26.4.4 or v26.4.5.

v26.4.4 (tenant user-bm7f6):

$ id
uid=1000940000(user) gid=0(root) groups=0(root),1000940000
$ groups
root 1000940000
$ sudo whoami
sudo: effective uid is not 0, is /usr/bin/sudo on a file system with the 'nosuid' option set or an NFS file system without root privileges?

v26.4.5 (tenant user-jtvxh):

$ id
uid=1000900000(user) gid=0(root) groups=0(root),1000900000
$ groups
root 1000900000
$ sudo whoami
sudo: effective uid is not 0, is /usr/bin/sudo on a file system with the 'nosuid' option set or an NFS file system without root privileges?

The workspace pods land on the restricted-v2 SCC, which sets allowPrivilegeEscalation: false and drops all capabilities. This may prevent setuid binaries from working regardless of the UID/passwd fix.

The UID cleanup from this PR is likely still a prerequisite for sudo to work, but it may not be sufficient on its own — the SCC/security context also needs to allow privilege escalation. Still investigating whether this is a cluster configuration issue or something that needs to be addressed in the DevWorkspace/CheCluster setup.

We need to figure out if there are specific SCC settings, CheCluster configuration, or DevWorkspace attributes required for sudo to work in DevSpaces — this will need to be addressed in the documentation for GA as part of the configuration requirements.

Tracking at rhpds/ansible-dev-tools-workspace#10.

cc @cgruver @alisonlhart @cidrblock

leogallego added a commit to rhpds/ansible-dev-tools-workspace that referenced this pull request Apr 23, 2026
v26.4.4 rollback confirmed the terminal crash is not image-specific.
Restoring v26.4.5 which includes the UID/passwd fix from
ansible/ansible-dev-tools#735.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
leogallego added a commit to rhpds/ansible-dev-tools-automation that referenced this pull request Apr 23, 2026
v26.4.4 rollback confirmed the terminal crash is not image-specific.
Restoring v26.4.5 which includes the UID/passwd fix from
ansible/ansible-dev-tools#735.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@cgruver
Copy link
Copy Markdown
Contributor

cgruver commented Apr 23, 2026

@leogallego I successfully started a workspace from this repo, main revision.

Sudo works as expected. When you are online today, ping me and we'll take a look at your config.

renovate Bot added a commit to sdwilsh/ansible-playbooks that referenced this pull request Apr 28, 2026
sdwilsh pushed a commit to sdwilsh/ansible-playbooks that referenced this pull request Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants